package com.zhangshuo.common.shiro;

import org.apache.shiro.cache.Cache;
import org.apache.shiro.cache.CacheException;
import org.apache.shiro.cache.CacheManager;

import javax.security.auth.DestroyFailedException;
import javax.security.auth.Destroyable;

/**
 * Created by Administrator on 2017/6/2 0002.
 */
public class ShiroSpringCacheManager implements CacheManager,Destroyable {

    private org.springframework.cache.CacheManager cacheManager;

    public ShiroSpringCacheManager(org.springframework.cache.CacheManager cacheManager){
        this.cacheManager = cacheManager;
    }

    private ShiroSpringCacheManager(){};

    @Override
    public <K, V> Cache<K, V> getCache(String name) throws CacheException {
        return new ShiroCache<>(cacheManager.getCache(name));
    }

    @Override
    public void destroy() throws DestroyFailedException {
        cacheManager =null ;
    }

    @Override
    public boolean isDestroyed() {
        return cacheManager==null;
    }
}
